<template>
  <!-- 订单支付详情 -->
  <section>
    <div style="border-bottom:1px solid #eee;padding-bottom:10px;">
      <el-page-header @back="goBack" content="账单详情"></el-page-header>
    </div>
    <br />
    <div class="visit_detail_box">
      <div class="userinfo p-sm">
        <p v-if="detail">
          <img v-if="detail.head!=''" :src="detail.head | imageUrl" class="patient_img" alt />
          <img v-else src="/img/unknown-avatar.4f0c79ac.png" class="patient_img" alt />
        </p>
        <p v-if="detail">
          <span style="font-size: 20px; margin-right: 20px; vertical-align: middle;">{{detail.name}}</span>
          <i class="glyphicon glyphicon-earphone" style="vertical-align: middle; font-size: 18px;"></i>
        </p>
        <!-- <div v-if="detail" class="user-field">
          <span>挂账：</span>
          {{detail.chargeToTheRoom? detail.chargeToTheRoom : 0 | changeMoneyToTwo}}
        </div>-->
        <div v-if="detail" class="user-field">
          <span>性别：</span>
          {{detail.sex | toSex}}
        </div>
        <div v-if="detail" class="user-field">
          <span>年龄：</span>
          <!-- <label v-if="detail.age>7">{{detail.age}}岁</label>
          <label v-if="detail.age<7">{{detail.age}}岁{{detail.sdfMonth}}月{{detail.sdfDay}}天</label>-->
          <label v-if="detail.age>17">{{detail.age}}</label>
          <label v-else>{{detail.birthday|toTimeContrast}}</label>
        </div>
        <!-- <div class="user-field">
        <span>婚姻状况：</span>
        </div>-->
        <div v-if="detail" class="user-field">
          <span>门诊号：</span>
          <span style="color: red;">{{detail.archivesCode}}</span>
        </div>
        <!-- <div v-if="detail" class="user-field">
          <span>就诊日期：</span>
          <span>{{detail.lastVisitTime | changeTime}}</span>
        </div>-->
        <!-- <div class="user-field">
        <span>初步诊断：</span>
        <span style="color: red;">￥ {{detail.money}}</span>
        </div>-->
      </div>
      <div class="user-content p-sm">
        <el-row style="margin:10px 0px;display:inline-block;width:100%;">
          <el-col :span="6">
            <label style="font-size:16px;">收费项目</label>
          </el-col>
          <el-col style="height:10px;" :span="6"></el-col>
          <el-col style="height:10px;" :span="6"></el-col>
          <!-- <el-col style="height:10px;" :span="6">
            <el-button style="float:right;" @click="$router.push({path:'/page/chargeIndex'})">返回</el-button>
          </el-col>-->
        </el-row>
        <el-row>
          <el-col :span="24">
            <table class="table-box">
              <thead>
                <tr>
                  <th v-if="isGo">
                    <el-checkbox
                      :indeterminate="isIndeterminate"
                      v-model="checkAll"
                      @change="handleCheckAllChange"
                    ></el-checkbox>
                  </th>
                  <th>收费名称</th>
                  <th>单价</th>
                  <th>数量</th>
                  <th>单位</th>
                  <th>折扣</th>
                  <th>是否套餐抵扣</th>
                  <th>抵扣数量</th>
                  <th>金额</th>
                  <th>科室</th>
                  <th>接诊医生</th>
                </tr>
              </thead>
              <tbody>
                <tr v-for="(item,index) in itemList" :key="index">
                  <template v-if="item.source !='13'">
                    <td v-if="isGo" class="return-item_td">
                      <el-checkbox-group
                        v-model="checkedAdmin"
                        @change="handleCheckedCitiesChange($event,item.sort,item.realityMoney)"
                      >
                        <el-checkbox :label="item.sort" :key="item.sort"></el-checkbox>
                      </el-checkbox-group>
                    </td>
                    <td>{{item.sourceName}}</td>
                    <td>{{item.unitPrice!=undefined?item.unitPrice:item.oneMoney }}</td>
                    <td>{{item.num?item.num:item.frequency}}</td>
                    <td>{{item.unitName}}</td>
                    <td>
                      <el-input
                        @blur="changeDis(item)"
                        :disabled="item.showDis"
                        v-model="item.discount"
                      >
                        <template slot="append">%</template>
                      </el-input>
                    </td>
                    <td style="text-align:center;">{{item.isDeduction==0?"否":"是"}}</td>
                    <td style="text-align:center;">{{item.deductionNum}}</td>
                    <td>
                      <el-input
                        v-if="item.realityMoney"
                        @blur="getDis(item)"
                        v-model="item.realityMoney"
                      >
                        <template slot="prepend">￥</template>
                      </el-input>
                      <el-input v-else v-model="item.realityMoney">
                        <template slot="prepend">￥</template>
                      </el-input>
                    </td>
                    <td>{{item.deptName}}</td>
                    <td>{{item.doctorName}}</td>
                  </template>
                </tr>
              </tbody>
            </table>
          </el-col>
        </el-row>
        <el-row v-if="tsList.length>0" class="moeny_box" style="margin-top:10px;">
          <el-col class="other" style="height:20px;font-size:16px;margin:5px 0;" :span="24">特殊收费项目</el-col>
          <el-col :span="24">
            <table class="table-box">
              <thead>
                <tr>
                  <th v-if="isGo">
                    <el-checkbox
                      :indeterminate="isCombo"
                      :disabled="true"
                      v-model="checkComboAll"
                      @change="changeCombo"
                    ></el-checkbox>
                  </th>
                  <th>收费名称</th>
                  <th>总价</th>
                  <!-- <th>现价</th> -->
                  <th>科室</th>
                  <th>接诊医生</th>
                  <th></th>
                  <th></th>
                  <th></th>
                  <th></th>
                  <th></th>
                </tr>
              </thead>
              <tbody>
                <tr v-for="(it,index) in tsList" :key="index">
                  <td v-if="isGo">
                    <el-checkbox-group
                      v-model="checkedCombo"
                      class="pay_check_box"
                      @change="tsChange($event,it.sort,it.totalPrice)"
                    >
                      <el-checkbox :label="it.sort" :key="it.sort"></el-checkbox>
                    </el-checkbox-group>
                  </td>
                  <td>{{it.sourceName}}</td>
                  <td>￥{{it.totalPrice}}</td>
                  <!-- <td></td> -->
                  <td>{{it.deptName}}</td>
                  <td>{{it.doctorName}}</td>
                  <td></td>
                  <td></td>
                  <td></td>
                  <td></td>
                  <td></td>
                </tr>
              </tbody>
            </table>
          </el-col>
        </el-row>
        <!-- <el-col class="money" style="text-align:right;" :span="6">
            <span>使用套餐：{{medicalComboName}} 核销 </span>
        </el-col>-->
        <el-row class="money_box">
          <el-col class="other" :span="18"></el-col>
          <el-col class="money" :span="6">
            <label>费用合计：</label>
            <span>￥{{total | changeMoneyToTwo}}</span>
          </el-col>
        </el-row>
        <el-row class="money_box">
          <el-col class="other" :span="18"></el-col>
          <el-col class="money" :span="6">
            <label>应收费用：</label>
            <span>￥{{totalMoney | changeMoneyToTwo}}</span>
          </el-col>
        </el-row>
        <el-row class="money_box">
          <el-col class="other" :span="18"></el-col>
          <el-col class="money" :span="6">
            <label>折扣金额：</label>
            <span>￥{{disAmount | changeMoneyToTwo}}</span>
          </el-col>
        </el-row>
        <!-- <el-row class="money_box">
          <el-col class="other" :span="18"></el-col>
          <el-col class="money" :span="6">
            <label>合计积分：</label>
            <span>{{integralNum}}</span>
          </el-col>
        </el-row>-->
        <el-row style="margin-top:20px;">
          <el-button
            style="float:right;"
            v-if="isGo"
            :loading="btnLoading"
            @click="onBeforeSubmit"
          >去结账</el-button>
          <el-button style="float:right;margin-right:10px;" @click="doPrint()">打印</el-button>
        </el-row>
      </div>
      <iframe
        v-if="showOrder"
        frameborder="0"
        height="0px"
        width="0px"
        ref="iframe"
        src="/print/chargerecipe.html"
      ></iframe>
    </div>
  </section>
</template>
<script>
export default {
  name: "chargeDetail",
  data() {
    return {
      dialogRecord: false,
      detail: "",
      checkedAdmin: [],
      checkAll: [],
      isIndeterminate: true,
      isCombo: true,
      checkedCombo: [],
      checkComboAll: [],
      itemList: [],
      tsList: [], //特殊项目
      reductionMoney: 0,
      return_label: "退费",
      returnMoney: 0,
      total: 0,
      totalMoney: 0.0, //总金额
      billPayways: [],
      dwList: [],
      disAmount: 0.0,
      integralNum: 0,
      doctorId: 0,
      deptId: 0,
      jfUse: "",
      levelProjectRelation: [],
      checkoutDis: 100, //检验折扣（辅助检查折扣2019.11.16----陈俊峰喊改的）
      examineDis: 100, //检查折扣
      cureDis: 100, //治疗折扣
      recipeDis: 100, //处方折扣
      therapyDis: 100, //诊疗折扣
      materialsDis: 100, //材料折扣
      otherDis: 100, //其他折扣
      discountEnum: [],
      showOrder: false,
      btnLoading: false,
      medicalComboId: "",
      medicalComboName: "", //使用套餐
      isGo: true,
    };
  },
  created() {
    this.getIntegralRuleById();
  },
  mounted() {
    this.getBasic();
    this.findUsUserById();
    this.getItemDetail();
    this.isGo = this.$route.query.isOrder ? false : true;
    // th.getCommonConfigByKey("会员折扣关联").then(res => {
    //   th.discountEnum = res;
    // });
  },
  methods: {
    findUsUserById() {
      let th = this;
      let uid = th.jieMi(th.$route.query.patientId);
      th.showLoading();
      th.$api
        .getThePatientLibraryById({ patientId: uid, hpId: th.adminUser.hpId })
        .then((res) => {
          if (res.executed) {
            th.detail = res.thePatientLibraryDetail;
            if (th.detail.levelId) {
              th.$api
                .getLevelEnumById({
                  id: th.detail.levelId,
                  hpId: th.adminUser.hpId,
                })
                .then((res) => {
                  th.showLoading(false);
                  if (res.executed) {
                    if (res.levelProjectRelation != undefined) {
                      th.levelProjectRelation = res.levelProjectRelation;
                      let list = res.levelProjectRelation;
                      for (let i = 0; i < list.length; i++) {
                        if (list[i].projectId == 1) {
                          th.examineDis = list[i].discount;
                        }
                        if (list[i].projectId == 2) {
                          th.checkoutDis = list[i].discount;
                        }
                        if (list[i].projectId == 3) {
                          th.cureDis = list[i].discount;
                        }
                        if (list[i].projectId == 4) {
                          th.recipeDis = list[i].discount;
                        }
                        if (list[i].projectId == 5) {
                          th.therapyDis = list[i].discount;
                        }
                        if (list[i].projectId == 6) {
                          th.materialsDis = list[i].discount;
                        }
                        if (list[i].projectId == 7) {
                          th.otherDis = list[i].discount;
                        }
                      }
                    }
                  }
                });
            } else {
              th.showLoading(false);
            }
            th.active = true;
            th.ispersonal = false;
          } else {
            th.showLoading(false);
            th.$message.error(res.message);
          }
        });
    },
    getItemDetail() {
      let th = this;
      let id = th.jieMi(th.$route.query.id);
      th.$api.findNoPayDetailListByNew({ cureId: id }).then((res) => {
        if (res.executed) {
          // let item = res.data;
          let item = res.data.cureDetailResponseDTOS;
          th.medicalComboName = res.data.medicalComboName;
          if (res.data.medicalComboId) {
            th.medicalComboId = res.data.medicalComboId;
          }
          let list = [];
          let _check = [];
          let _tscheck = [];
          let total = 0; //折扣后总额
          let _totalMoney = 0; //未折扣总额
          let _disAmount = 0; //折扣总金额
          if (item.length > 0) {
            th.deptId = item[0].deptId;
            th.doctorId = item[0].doctorId;
          }
          // let typeId;
          // //获取source属于什么分类
          // for (let i = 0; i < th.discountEnum.length; i++) {
          //   let data = th.discountEnum[i];
          //   let index = data.desc.indexOf(source + "");
          //   if (index != -1) {
          //     typeId = data.id;
          //     break;
          //   }
          // }
          for (let i = 0; i < item.length; i++) {
            let arr = {
              discount: 100,
              realityMoney: "",
              discountMoney: "",
              showDis: false,
            };
            //1:挂号费 2处方 3治疗 4实验室检查 5:辅助检查 6：材料费 7：其他收费 8:西药 9:中药 10:零售药
            arr = Object.assign(arr, item[i]);
            if (arr.isHealthDiscount == 1 && res.data.medicalComboName == "") {
              arr.discount = "95";
            }
            if (arr.isDiscount == 1) {
              if (arr.source == 1) {
                arr.discount = th.therapyDis; //诊疗折扣
              }
              if (
                arr.source == 2 ||
                arr.source == 8 ||
                arr.source == 9 ||
                arr.source == 10
              ) {
                arr.discount = th.recipeDis; //处方折扣
              }
              if (arr.source == 3) {
                arr.discount = th.cureDis; //治疗折扣
              }
              if (arr.source == 5) {
                arr.discount = th.checkoutDis; //辅助检查折扣
              }
              if (arr.source == 4) {
                arr.discount = th.examineDis; //检查折扣
              }
              if (arr.source == 6) {
                arr.discount = th.materialsDis; //材料折扣
              }
              if (arr.source == 7) {
                arr.discount = th.otherDis; //其他折扣
              }
            } else {
              arr.showDis = true;
            }
            if (item[i].totalPrice != undefined) {
              arr.realityMoney = Number(
                item[i].totalPrice * Number(arr.discount / 100).toFixed(2)
              ).toFixed(2);
              arr.discountMoney =
                Number(item[i].totalPrice) *
                ((100 - Number(arr.discount)) / 100).toFixed(2);
              total += Number(arr.realityMoney);
              _totalMoney += Number(item[i].totalPrice);
              _disAmount += Number(arr.discountMoney);
            }
            th.disAmount = _disAmount;
            _check.push(item[i].sort);
            _tscheck.push(item[i].sort);
            list.push(arr);
          }
          th.totalMoney = total.toFixed(2);
          th.total = _totalMoney.toFixed(2);
          if (th.jfUse) {
            if (th.total > th.jfUse.useNum) {
              let _total = parseInt(th.total);
              //向上取整 Math.ceil(5/2)
              //向下取整  Math.floor(5/2)
              th.integralNum =
                Math.floor(_total / Number(th.jfUse.useNum)) * th.jfUse.getNum;
            } else {
              th.integralNum = 0;
            }
          } else {
            th.integralNum = 0;
          }
          th.checkedAdmin = _check;
          th.checkedCombo = _tscheck;
          let tsList = [];
          list.filter((it) => {
            if (it.source == 13) {
              tsList.push(it);
            }
          });
          th.tsList = tsList;
          list = list.filter((it) => {
            if (it.source != 13) {
              return it;
            }
          });

          th.itemList = list;
        } else {
          th.$message.error(res.message);
        }
      });
    },
    getBasic() {
      let th = this;
      th.getCommonConfigByKey("药品剂量单位").then((res) => {
        th.dwList = res;
      });
    },
    changeDis(item) {
      item.discount = Number(item.discount) < 0 ? 100 : Number(item.discount);
      let oldMoney = Number(item.realityMoney);
      item.realityMoney = Number(
        item.totalPrice * (item.discount / 100)
      ).toFixed(2);
      item.totalMoney = Number(item.totalPrice * (item.discount / 100)).toFixed(
        2
      );
      item.discountMoney = Number(item.totalPrice - item.realityMoney).toFixed(
        2
      );
      this.totalMoney =
        Number(this.totalMoney) - Number(oldMoney) + Number(item.realityMoney);
      if (this.totalMoney > this.jfUse.useNum) {
        let _total = parseInt(this.totalMoney);
        this.integralNum =
          Math.ceil(_total / Number(this.jfUse.useNum)) * this.jfUse.getNum;
      } else {
        this.integralNum = 0;
      }
      this.getDisMoney();
    },
    //获取折扣金额
    getDisMoney() {
      let th = this;
      let item = th.itemList;
      let _total = 0;
      let total = 0;
      let _disMoney = 0;
      for (let i = 0; i < item.length; i++) {
        total += Number(item[i].realityMoney);
        _total += Number(item[i].totalPrice);
        _disMoney += Number(item[i].discountMoney);
      }
      if (th.total > th.jfUse.useNum) {
        let _total = parseInt(th.total);
        //向上取整 Math.ceil(5/2)
        //向下取整  Math.floor(5/2)
        th.integralNum =
          Math.ceil(_total / Number(th.jfUse.useNum)) * th.jfUse.getNum;
      } else {
        th.integralNum = 0;
      }
      th.total = _total.toFixed(2);
      th.totalMoney = total.toFixed(2);
      th.disAmount = _disMoney.toFixed(2);
    },
    handleCheckAllChange(val) {
      let th = this;
      let checked = [];
      for (var i = 0; i < th.itemList.length; i++) {
        checked.push(th.itemList[i].sort);
      }
      th.checkedAdmin = val ? checked : [];
      if (th.checkedAdmin.length == 0) {
        th.totalMoney = 0.0;
        th.total = 0.0;
        th.disAmount = 0.0;
      } else {
        th.getDisMoney();
      }
      th.isCombo = false;
    },
    handleCheckedCitiesChange(value, id, money) {
      let th = this;
      let checkedCount = value.length;
      th.checkComboAll = checkedCount === th.tsList.length;
      th.isCombo = checkedCount > 0 && checkedCount < th.tsList.length;
      let bools = value.includes(id);
      if (bools == true) {
        th.totalMoney = Number(th.totalMoney) + Number(money);
        th.totalMoney = th.totalMoney.toFixed(2);
      } else {
        th.totalMoney = Number(th.totalMoney) - Number(money);
        th.totalMoney = th.totalMoney.toFixed(2);
      }
    },
    changeCombo(val) {
      let th = this;
      let checked = [];
      for (var i = 0; i < th.tsList.length; i++) {
        checked.push(th.tsList[i].sort);
      }
      th.checkedCombo = val ? checked : [];
      if (th.checkedCombo.length == 0) {
        let tsTotalMoney = 0;
        th.tsList.forEach((it) => {
          tsTotalMoney += Number(it.totalPrice);
        });
        if (tsTotalMoney) {
          th.totalMoney = Number(th.totalMoney) - Number(tsTotalMoney);
          th.totalMoney = Number(th.totalMoney).toFixed(2);
          th.total = Number(th.totalMoney).toFixed(2);
        }
      } else {
        th.getDisMoney();
      }
      th.isCombo = false;
    },
    //特殊收费
    tsChange(value, id, money) {
      let th = this;
      let checkedCount = value.length;
      th.checkAll = checkedCount === th.itemList.length;
      th.isCombo = checkedCount > 0 && checkedCount < th.itemList.length;
      let bools = value.includes(id);
      if (bools == true) {
        th.totalMoney = Number(th.totalMoney) + Number(money);
        th.totalMoney = th.totalMoney.toFixed(2);
      } else {
        th.totalMoney = Number(th.totalMoney) - Number(money);
        th.totalMoney = th.totalMoney.toFixed(2);
      }
    },
    getDis(item) {
      let th = this;
      if (item.showDis) {
        item.realityMoney = item.totalPrice;
      } else {
        if (item.discount == 100) {
          if (Number(item.realityMoney) > Number(item.totalPrice)) {
            item.realityMoney = item.totalPrice;
            item.discount = 100;
          } else {
            let num =
              (Number(item.realityMoney) / Number(item.totalPrice)) * 100;
            num = (Number(item.realityMoney) / Number(item.totalPrice)) * 100;
            item.discount = parseInt(num);
          }
        } else {
          if (Number(item.realityMoney) > Number(item.totalPrice)) {
            item.realityMoney = item.totalPrice;
            item.discount = 100;
          } else {
            let num =
              (Number(item.realityMoney) / Number(item.totalPrice)) * 100;
            num = (Number(item.realityMoney) / Number(item.totalPrice)) * 100;
            item.discount = parseInt(num);
          }
        }
      }
      th.totalMoney =
        Number(th.totalMoney) -
        Number(item.totalPrice) +
        Number(item.realityMoney);
      th.totalMoney = th.totalMoney.toFixed(2);
    },
    //预先提交提示
    onBeforeSubmit() {
      const th = this;
      //判断是否有套餐id
      if (th.medicalComboId) {
        let j = {
          id: th.medicalComboId,
        };
        th.btnLoading = true;
        th.$api
          .getUserPackageItemById(j)
          .then((res) => {
            if (res.executed) {
              // if (res.dataBody.payStatus == 0) fn();
              // else
              th.openDetail();
            }
            th.btnLoading = false;
          })
          .catch((res) => {
            th.btnLoading = false;
          });
      } else {
        th.openDetail();
      }
      const fn = function () {
        th.$confirm("检测您套餐未支付，将不会参与核销?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
          center: true,
        })
          .then(() => {
            th.openDetail();
          })
          .catch(() => {});
      };
    },
    openDetail() {
      let th = this;
      let _item = th.itemList;
      let _combo = th.tsList;
      let check = th.checkedAdmin;
      let item = [];
      th.btnLoading = true;
      let _countMoney = 0;
      let _discountMoney = 0;

      if (_item.length > 0) {
        _item.map((it) => {
          check.map((obj) => {
            if (it.sort == obj) {
              if (it.sourceName != "" && it.totalPrice != null) {
                let arr = {};
                arr = Object.assign(arr, it);
                arr.frequency = it.num;
                arr.oneMoney = it.unitPrice;
                arr.preferential = it.preferential;
                arr.preferentialType = it.preferentialType;
                //是否核销---新加2019.11.15
                arr.isWriteOff = it.isDeduction;
                arr.writeOffFrequency = it.deductionNum;
                //=====
                (arr.patientId = th.jieMi(th.$route.query.patientId)),
                  (arr.totalMoney = Number(it.totalPrice).toFixed(2));
                arr.realityMoney = Number(it.realityMoney).toFixed(2);
                arr.discountMoney = Number(it.discountMoney).toFixed(2);
                _countMoney += Number(it.totalPrice);
                _discountMoney += Number(it.discountMoney);
                item.push(arr);
              }
            }
          });
        });
      }

      // for (let i = 0; i < _item.length; i++) {
      //   for (let j = 0; j < th.checkedAdmin.length; j++) {
      //     if (_item[i].sort == th.checkedAdmin[j]) {
      //       if (_item[i].sourceName != "" && _item[i].totalPrice != null) {
      //         let arr = {
      //           totalMoney: "",
      //           realityMoney: 0,
      //           integralNum: 0,
      //           patientId: "",
      //         };
      //         arr = Object.assign(arr, _item[i]);
      //         arr.frequency = _item[i].num;
      //         arr.oneMoney = _item[i].unitPrice;
      //         //是否核销---新加2019.11.15
      //         arr.isWriteOff = _item[i].isDeduction;
      //         arr.writeOffFrequency = _item[i].deductionNum;
      //         //=====
      //         (arr.patientId = th.jieMi(th.$route.query.patientId)),
      //           (arr.totalMoney = Number(_item[i].totalPrice).toFixed(2));
      //         arr.realityMoney = Number(_item[i].realityMoney).toFixed(2);
      //         arr.discountMoney = Number(_item[i].discountMoney).toFixed(2);
      //         _countMoney += Number(_item[i].totalPrice);
      //         _discountMoney += Number(_item[i].discountMoney);
      //         item.push(arr);
      //       }
      //     }
      //   }
      // }

      for (let i = 0; i < _combo.length; i++) {
        for (let j = 0; j < th.checkedCombo.length; j++) {
          if (_combo[i].sort == th.checkedCombo[j]) {
            if (_combo[i].sourceName != "" && _combo[i].totalPrice != null) {
              let arr = {
                totalMoney: "",
                realityMoney: 0,
                oneMoney: 0,
                integralNum: 0,
                patientId: "",
              };
              arr = Object.assign(arr, _combo[i]);
              arr.frequency = 1;
              arr.oneMoney = Number(_combo[i].totalPrice).toFixed(2);
              //是否核销---新加2019.11.15
              arr.isWriteOff = _combo[i].isDeduction;
              arr.writeOffFrequency = _combo[i].deductionNum;
              //=====
              arr.patientId = th.jieMi(th.$route.query.patientId);
              arr.totalMoney = Number(_combo[i].totalPrice).toFixed(2);
              arr.realityMoney = Number(_combo[i].totalPrice).toFixed(2);
              arr.discountMoney = 0;
              _countMoney += Number(_combo[i].totalPrice);
              _discountMoney += 0;
              item.push(arr);
            }
          }
        }
      }
      _countMoney = _countMoney.toFixed(2);
      _discountMoney = _discountMoney.toFixed(2);
      let finish = 0;
      if (th.itemList.length == th.checkedAdmin.length) {
        finish = 1;
      }
      let j = {
        source: 1,
        hpId: th.adminUser.hpId,
        sourceId: th.jieMi(th.$route.query.id),
        totalMoney: _countMoney,
        finishOrder: finish,
        realityMoney: th.totalMoney,
        recordNum: 0, //总积分数
        discountMoney: _discountMoney,
        orderItemsJSON: JSON.stringify(item),
        patientId: th.jieMi(th.$route.query.patientId),
        deptId: th.deptId,
        doctorId: th.doctorId,
        userPackageItemId: th.medicalComboId,
      };
      th.$api.createOrder(j).then((res) => {
        if (res.executed == true) {
          //th.$message.success(res.message);
          th.btnLoading = false;
          th.$router.push({
            path: "/page/paycharge",
            query: th.getUrlToken({
              // total: th.totalMoney,
              orderId: res.dataBody.orderId,
              orderCode: res.dataBody.orderCode,
              id: th.$route.query.id,
              patientId: th.$route.query.patientId,
            }),
          });
        } else {
          th.$message.error(res.message);
          th.btnLoading = false;
        }
      });
    },
    getIntegralRuleById() {
      let th = this;
      th.$api
        .getIntegralRuleById({ hpId: th.adminUser.hpId, type: 1 })
        .then((res) => {
          if (res.executed) {
            th.jfUse = res.integralRuleList[0];
          }
        });
    },
    goBack() {
      this.$router.go(-1);
    },
    doPrint() {
      let th = this;
      th.showOrder = true;
      th.showLoading();
      setTimeout(function () {
        th.iframeContent = th.$refs.iframe.contentWindow;
        th.iframeContent.postMessage(
          {
            cmd: "postJson",
            params: JSON.stringify({
              detail: th.detail,
              disAmount: th.disAmount,
              list: th.itemList,
              doctor: "",
              dept: "",
              special: th.tsList, //特殊收费
              billPayways: th.billPayways,
              logo: th.adminUser.printLogo,
              orderCode: th.$route.query.orderCode,
              total: th.totalMoney,
              hospitalName: th.adminUser.hospitalName,
            }),
          },
          "*"
        );
      }, 500);
      setTimeout(function () {
        th.showLoading(false);
      }, 2000);
    },
  },
};
</script>
<style lang="scss" scoped>
@import "../_css/detail.scss";
.patient_img {
  border: 1px solid #ddd;
  border-radius: 5px;
  display: inline-block;
  width: 100px;
  height: 100px;
}
.durg_title {
  display: inline-block;
  width: 100%;
  font-size: 16px;
  border-bottom: 1px solid #ddd;
  padding-bottom: 10px;
  margin-bottom: 10px;
}

.money_box {
  margin-top: 10px;
  display: inline-block;
  width: 100%;
  .other {
    height: 10px;
    display: inline-block;
  }
  .money {
    text-align: right;
    padding-right: 10px;
    display: inline-block;
  }
}
.printOrder {
  display: inline-block;
  width: 100%;
}
</style>

